package com.zy.project.system.menu.entity.base;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zy.core.common.constant.enums.MenuTypeEnum;
import com.zy.core.common.constant.enums.StatusEnum;
import com.zy.core.common.constant.system.SysConstant;
import com.zy.core.data.jpa.support.entity.BaseEntity;
import com.zy.project.system.menu.entity.SystemMenu;
import com.zy.project.system.permission.entity.SystemPermission;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * 菜单实体
 * Package: com.zy.project.system.menu.entity
 * <p>
 * Description： TODO
 * <p>
 * Author: zhangyu
 * <p>
 * Date: Created in 2018-12-8 15:39
 * <p>
 * Copyright: Copyright (c) 2018
 * <p>
 * Version: 0.0.1
 * <p>
 * Modified By:
 */
@Getter
@Setter
@MappedSuperclass
public class BaseSystemMenu extends BaseEntity {
    /**
     * 菜单ID
     */
    @Id
    @GenericGenerator(name ="jpa-uuid", strategy = "uuid")
    @GeneratedValue(generator = "jpa-uuid")
    @Column(name = "id")
    private String id;

    /**
     * 菜单名称
     */
    @Column(name = "name")
    private String name;

    /**
     * 显示顺序
     */
    @Column(name = "order_num")
    private Integer orderNum;

    /**
     * 菜单URL
     */
    @Column(name = "url")
    private String url;

    /**
     * 类型
     */
    @Type(type = SysConstant.DB_CONVERT_NAME)
    @Column(name = "menu_type")
    private MenuTypeEnum menuType;

    /**
     * 菜单状态
     */
    @Type(type = SysConstant.DB_CONVERT_NAME)
    @Column(name = "visible")
    private StatusEnum visible;

    /**
     * 菜单图标
     */
    @Column(name = "icon")
    private String icon;

    /**
     * 创建者
     */
    @Column(name = "create_by")
    private String createBy;

    /**
     * 创建时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_date")
    private Date createDate;

    /**
     * 更新者
     */
    @Column(name = "update_by")
    private String updateBy;

    /**
     * 更新时间
     */
    @Column(name = "update_date")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date updateDate;

    /** 备注 */
    @Column(name = "remark")
    private String remark;


    /**
     * 子菜单
     */
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent", fetch = FetchType.LAZY)
    @JSONField(serialize=false)
    private Set<SystemMenu> childrens;

    /**
     * 父菜单
     */
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="parent_id")
    @JSONField(serialize=false)
    private SystemMenu parent;


    /**
     * 权限id
     */
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "permission_id")
    @JSONField(serialize=false)
    private SystemPermission permission;
}
